package com.j48.entrancegurad.mapper;

import com.j48.entrancegurad.model.Power;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * power表操作
 */
@Repository
@Mapper
public interface PowerMapper {
    /**
     * 查询所有权限
     *
     * @return 权限列表
     */
    @Select("select * from `power`")
    public ArrayList<Power> selectAll();

    /**
     * 按名称查询权限
     * @param power 所需查询的权限
     * @return 查询结果
     */
    @Select("select * from `power` where power_name=#{power_name}")
    public Power selectByName(Power power);
    /**
     * 按编号查询权限
     * @param power 所需查询的权限
     * @return 查询结果
     */
    @Select("select * from `power` where power_id=#{power_id}")
    public Power selectById(Power power);

    /**
     * 按编号查询权限
     * @param power 所需查询的权限
     * @return 查询结果
     */
    @Select("select * from `power` where power_id=#{power_id}")
    public ArrayList<Power> selectBypowerId(Power power);

    /**
     * 查询当前权限是否是1级菜单
     * @param power
     * @return
     */
    @Select("select * from `power` having #{power_id} in (select power_id from power where power_level=1) and power_id=#{power_id}")
    public Power selectMainMenu(Power power);
    /**
     * 查询当前权限是否是2级菜单
     * @param power
     * @return
     */
    @Select("select * from `power` having #{power_id} in (select power_id from power where power_level=2) and power_id=#{power_id}")
    public Power selectLowerMenu(Power power);

    /**
     * 查询当前权限的父级菜单
     * @param power
     * @return
     */
    @Select("select * from `power` where power_id=#{power_parent_id}")
    public Power selectParentMenu(Power power);
    /**
     * 查询当前权限的子级菜单
     * @param power
     * @return
     */
    @Select("select * from `power` where power_parent_id=#{power_id}")
    public ArrayList<Power> selectChildrenMenu(Power power);
}
